<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title></title>
    <link rel="stylesheet" type="text/css" href="/static/css/babyinvite/common.css">
    <link rel="stylesheet" type="text/css" href="/static/css/babyinvite/style.css">
    <script type="text/javascript" src="/static/js/babyinvite/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/static/js/babyinvite/popups.js"></script>
    <script>
        (function (doc, win) {
            var docEl = doc.documentElement,
                resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
                recalc = function () {
                    var clientWidth = docEl.clientWidth;
                    if (!clientWidth) return;
                    if (clientWidth >= 640) {
                        docEl.style.fontSize = '100px';
                    } else {
                        docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
                    }
                };
            if (!doc.addEventListener) return;
            win.addEventListener(resizeEvt, recalc, false);
            doc.addEventListener('DOMContentLoaded', recalc, false);
        })(document, window);
    </script>
</head>
<body>

<div class="registered">
    <div class="int" style="margin-top: 1.9rem;">
        <input class="tel" type="text" placeholder="请输入手机号码">
    </div>
   <!-- <div class="int">
        <input class="code" type="text" placeholder="请输入验证码">
        <div onclick="countdownClick()" class="get_code">获取验证码</div>
    </div>-->
    <div class="int">
        <input class="password" type="password" placeholder="请输入密码">
    </div>
    <div class="int">
        <input class="password passwords" type="password" placeholder="请输再次确认密码">
    </div>
    <div class="int">
        <input id="user_invite" class="inviteCode" value="{$invite}" type="text" placeholder="用户的邀请码（选填）">
    </div>
    <div id="error_msg" class="error_msg">
    </div>

    <div onclick="registered()" class="sure">提交</div>
    <div id="downapk_url" class="downapk_url"></div>

</div>

</body>
</html>


<script type="text/javascript">
    //获取链接
    var url = window.location.href;
    var start = url.indexOf("://") + 3;
    var end = url.indexOf("/api/");
    var post_url = url.substring(start, end);
    console.log(post_url);
    var countdown = 60

    window.onload = function () {
        //获取参数
        var query = window.location.search.substring(1);
        $('#downapk_url').append('<a href="http://app.shiyuapp.com/">你已注册，请点击下载！</a>')
    };

    function registered() {
        /*if ($('.code').val() == '') {
            jqtoast('请输入验证码');
            return false
        }*/
        if ($('.password').val() == '') {
            jqtoast('请输入密码');
            return false
        }
        if ($('.passwords').val() == '') {
            jqtoast('请输再次确认密码');
            return false
        }

        if ($('.passwords').val() != $('.password').val()) {
            jqtoast('两次密码不一致');
            return false
        }

        $.ajax({
            async: false,
            type: "post",
            url: "http://" + post_url + "/api/register",
            data: {
                mobile: $('.tel').val(),
                password: $('.password').val(),
                repassword: $('.passwords').val(),
                invite_code: $('.inviteCode').val(),
                //code: $('.code').val()
            },
            dataType: "json",
            success: function (res) {
                if(res.code == 0){
                    jqtoast(res.msg);
                    window.location.href = "http://app.shiyuapp.com/";
                }else{
                    jqtoast(res.msg);
                }
            },
            error: function (data) {
                alert(data.result);
            }
        });
    }

    function countdownClick() { // 倒计时
        if ($('.tel').val().length !== 11) {
            jqtoast('请输入正确手机号码');
            return false
        }

        $.ajax({
            async: false,
            type: "post",
            url: "http://" + post_url + "/api/get_sms_verify_code",
            data: {
                mobile: $('.tel').val(),
                type: 1
            },
            dataType: "json",
            success: function (res) {
                if(res.code == 0){
                    jqtoast(res.msg);
                    settime();
                }else{
                    jqtoast(res.msg);
                }
            },
            error: function (data) {
                alert(data.result);
            }
        });
    }


    function settime(obj) {
        if (countdown == 0) {
            $('.get_code').html(获取验证码);
            countdown = 60;
            return
        } else {
            $('.get_code').html("重新发送(" + countdown + ")");
            countdown--
        }
        setTimeout(function () {
                settime(obj)
            }
            , 1000)
    }
</script>